package test9;

public class Test1 {
    public static void main(String[] args) {
        Student[] studentsArry = new Student[3];

        Student st1 = new Student(1,"xiaoming",25);
        Student st2 = new Student(2,"lihua",22);
        Student st3 = new Student(3,"weizhihui",26);

        studentsArry[0] = st1;
        studentsArry[1] = st2;
        studentsArry[2] = st3;

        int index = getIndex(studentsArry,4);
        if (index >= 0){
            studentsArry[index] = null;
            printStudent(studentsArry);
        }else {
            System.out.println("该学生不存在");
        }

    }
    public static int getIndex(Student[] students,int id){
        for (int i = 0; i < students.length; i++) {
            Student student = students[i];
            if (student != null){
                int sid = student.getId();
                if (sid == id){
                    return i;
                }
            }
        }
        return -1;
    }

    public static void printStudent(Student[] arry){
        for (int i = 0; i < arry.length; i++) {
            Student student = arry[i];
            if(student != null){
                System.out.println(student.getId()+","+student.getName()+","+student.getAge());
            }
        }
    }

}
